/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui.tbl;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import org.tnmk.worktime.gui.HistoryController;
import org.tnmk.worktime.gui.MainFrame;
import org.tnmk.worktime.service.dao.entry.SessionEntry;
import org.tnmk.worktime.service.dao.entry.SessionType;

/**
 *
 * @author Administrator
 */
public class SessionTypeCellRenderer extends DecorateDefaultTableCellRenderer {
//  private static final Logger log = Logger.getLogger(SessionTypeCellRenderer.class.getSimpleName());

  private static final Color OFF_BG_COLOR = new Color(240, 240, 240);
  private static final Color WORK_BG_COLOR = UIManager.getColor("Table.dropCellBackground");
  private final MainFrame frame;

  public SessionTypeCellRenderer(MainFrame frame) {
    super();
    this.frame = frame;
  }

  @Override
  public Component getTableCellRendererComponent(JLabel comp, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Integer sessionId = (Integer) table.getValueAt(row, HistoryController.COL_ID);
    SessionEntry session = frame.getService().findSession(sessionId);
    if (session.getType() == SessionType.Work) {
      comp.setBackground(WORK_BG_COLOR);
    } else {
      comp.setBackground(OFF_BG_COLOR);
    }
    return comp;
  }
}
